home *** CD-ROM | disk | FTP | other *** search
/ MacWorld Secrets (4th Edition) / Mac Secrets CD 4th Ed.toast / Apple Advanced Technologies / Apple Speech Technologies 1.5 / PlainTalk Developer Info / Speech Recognition Manager SDK / SR Sample Code / IM SR Example / MyCallPersonInPath.c < prev    next >
C/C++ Source or Header  |  1996-04-10  |  2KB  |  54 lines

  1. #include <SpeechRecognition.h>
  2. #include <stdio.h>
  3.  
  4. OSErr MyCallPersonInPath (SRPath recognizedPath);
  5.  
  6. /*
  7. const char *    kPersonNames[] = {"Arlo", "Matt", "Brent", "my wife", NULL};
  8. */
  9.  
  10. extern const char *    kPersonNames[];
  11. const char *        kPhoneNumbers[] = {"555-4567", "555-4568", "555-4569", 
  12.                                                                 "(123) 456-7890"};
  13.  
  14. OSErr MyCallPersonInPath (SRPath recognizedPath)
  15. {
  16.     OSErr            myErr = noErr;
  17.     SRLanguageObject    myPersonLM;
  18.     
  19.     /* recognizedPath has two sub-elements:                         */
  20.     /* "<call>" (SRLanguageModel), "<person>" (SRLanguageModel)     */
  21.     /* we get the second sub-element                                 */
  22.     myErr = SRGetIndexedItem (recognizedPath, &myPersonLM, 1);
  23.     if (!myErr) {
  24.         SRLanguageObject    myPhraseSpoken;
  25.         
  26.         /* myPersonLM will have one sub-element, the name spoken (a phrase) */
  27.         myErr = SRGetIndexedItem (myPersonLM, &myPhraseSpoken, 0);
  28.         if (!myErr) {
  29.             long     myRefCon;
  30.             Size    myLen = sizeof (myRefCon);
  31.  
  32.             /* When we built the language model, we set the refcon to the index */
  33.             /* of names in a list. The phone numbers in kPhoneNumbers correspond */
  34.             /* to those names */
  35.             myErr = SRGetProperty (myPhraseSpoken, kSRRefCon, &myRefCon, &myLen);
  36.             if (!myErr) {
  37.                 short    myArrayIndex = myRefCon;
  38.                 
  39.                 printf ("Now calling %s. Dialing %s.\n", 
  40.                         kPersonNames[myArrayIndex], kPhoneNumbers[myArrayIndex]);
  41.             }
  42.             
  43.             /* release myPhraseSpoken when done with it */
  44.             myErr = SRReleaseObject (myPhraseSpoken);
  45.         }
  46.         
  47.         /* release myPersonLM when done with it */
  48.         myErr = SRReleaseObject (myPersonLM);
  49.     }
  50.     
  51.     return myErr;
  52. }
  53.  
  54.